<template>
  <basic-container>
    <avue-crud
        v-if="tableOption"
        v-bind="bindVal"
        v-on="onEvent"
        v-model:page="page"
        v-model="startForm">
      <template v-for="(column,index) in columns" :slot="column.prop" slot-scope="{type,size,row}">
        <component :is="column.columnComponent" :row="row" :rowKey="column.prop" :column="column"></component>
      </template>
      <template #menu="scope">
        <el-button v-if="![-10,20].includes(scope.row.procHandlerState)" :type="scope.type" text
                   :disabled="scope.disabled"
                   :size="scope.size"
                   @click="cancelActEvent(scope.row)">取消
        </el-button>
      </template>
    </avue-crud>
  </basic-container>
</template>

<script>
import {createDynamicMixin} from "@/mixins/startCrud.js"
import startActApi from "@/api/start/activiti/core/startActApi";
import autoRouter from "@/views/start/activiti/autoRouter";

const optionConf = {
  name: "start/activiti/myActBusinessOption",
  optionPath: 'start/activiti/actBusiness',
  apiPath: 'start/activiti/core/startAct',
  list: "pageMyBusiness",
  permissionBtnHandler: {
    delBtn: (vm, row, defaultValue) => {
      return row.procHandlerState === -10
    }
  }
}
//
export default {
  name: "myApply",
  mixins: [createDynamicMixin(optionConf)],
  methods: {
    loadCrudOptionBefore(option) {
      option.addBtn = false;
      option.delBtn = true;
      option.viewBtn = true;
      option.menuType = false;

    },
    beforeLoadDataSource(search) {
      search.start_order_createTime = "desc"
    },
    loadCrudColumnBefore(column) {
      if (column.prop !== 'procStartUserFinalName') {
        return
      }
      column.hide = true
      column.showColumn = false;
    },

    beforeOpenViewDialog(row) {
      let title = "流程详情【" + row.procDefName + "】" + row.procStartUserFinalName

      this.$router.push({path: autoRouter.paths.procDetailPath + "/" + row.id+"/"+title})
      return true;
    },
    cancelActEvent(row) {
      let option = {}
      let msgBoxDone
      option.beforeClose = (action, instance, done) => {
        msgBoxDone = done;
        if (action !== "confirm") {
          done();
          return
        }
        startActApi.cancelApply(row.id, instance.inputValue).then(res => {
          done();
          this.refreshChange()
        }).catch(err => {
          console.log(err)
        })
      }
      this.$prompt("系统提示", `您确定要取消【${row.procDefName}】此流程申请`, option);
    },
    rowDel(row, index) {
      this.$confirm(`此操作将永久删除草稿为【${row.procDefName}】的数据！ 是否继续?`, '系统提示', {
        confirmButtonText: '是', cancelButtonText: '否', type: 'warning'
      }).then(() => {
        return startActApi.deleteActById(row.id)
      }).then(res => {
        this.loadRemoteDataSources()
        this.$message.success('删除成功')
      })

    },


  }

}
</script>

<style scoped>

</style>
